package cn.group.hotel2.controller;

import cn.group.hotel2.pojo.dto.RoomCheckInAddNewDTO;
import cn.group.hotel2.pojo.dto.RoomCheckInUpdateDTO;
import cn.group.hotel2.pojo.vo.RoomCheckInListCountVO;
import cn.group.hotel2.pojo.vo.RoomCheckInListItemVO;
import cn.group.hotel2.pojo.vo.RoomCheckInStandardVO;
import cn.group.hotel2.service.IRoomCheckInService;
import cn.group.hotel2.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.hibernate.validator.constraints.Range;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * 处理入住登记相关请求的控制器
 *
 * @author wcl
 * @version 0.0.1
 * @date 2022/11/21
 */

@Slf4j
@Valid
@RestController
@RequestMapping("/checkIn")
@Api(tags = "01 入住登记管理模块")
public class RoomCheckInController {

    @Autowired
    private IRoomCheckInService roomCheckInService;

    public RoomCheckInController() {
        log.debug("创建控制器对象：RoomCheckInController");
    }

    @ApiOperation("新增入住登记")
    @ApiOperationSupport(order = 100)
    @PostMapping("/add-new")
    public JsonResult<Void> addNew(@Valid RoomCheckInAddNewDTO roomCheckInAddNewDTO) {
        log.debug("开始处理【新增入住登记】的请求，参数：{}", roomCheckInAddNewDTO);
        roomCheckInService.addNew(roomCheckInAddNewDTO);
        log.debug("新增入住登记成功！");
        return JsonResult.ok();
    }

    @ApiOperation("根据id删除入住登记")
    @ApiOperationSupport(order = 200)
    @ApiImplicitParam(name="id",value = "入住登记id",required = true,dataType = "long")
    @PostMapping("/{id:[0-9]+}/delete")
    public JsonResult<Void> deleteById(@Range(min = 1,message = "删除入住登记失败,请填写有效的大于0的id") @PathVariable Long id) {
        log.debug("开始处理【根据id删除入住登记】的请求,参数:{}", id);
        roomCheckInService.deleteById(id);
        log.debug("删除入住登记成功!");
        return JsonResult.ok();
    }

    @ApiOperation("根据入住登记id修改入住登记详情")
    @ApiOperationSupport(order = 300)
    @ApiImplicitParam(name="id",value = "入住登记id",required = true,dataType = "long")
    @PostMapping("/{id:[0-9]+}/update")
    public JsonResult<Void> update(@PathVariable Long id, RoomCheckInUpdateDTO roomCheckInUpdateDTO) {
        log.debug("开始处理【根据入住登记id修改入住登记详情】的请求,id参数:{},数据参数:{}", id, roomCheckInUpdateDTO);
        roomCheckInService.updateById(id, roomCheckInUpdateDTO);
        log.debug("修改数据成功!");
        return JsonResult.ok();
    }

    @ApiOperation("根据id查询入住登记详情")
    @ApiOperationSupport(order = 405)
    @GetMapping("/{id:[0-9]+}/getStandardById")
    @ApiImplicitParam(name = "id", value = "入住登记id", required = true, dataType = "long")
    public JsonResult<RoomCheckInStandardVO> getStandardById(@Range(min = 1, message = "查询入住登记详情失败,请填写有效的大于0的id") @PathVariable Long id){
        log.debug("开始处理【根据id查询入住登记详情】请求,参数:{}", id);
        RoomCheckInStandardVO queryResult = roomCheckInService.getStandardById(id);
        return JsonResult.ok(queryResult);
    }

    @ApiOperation("查询入住登记列表")
    @ApiOperationSupport(order = 410)
    @GetMapping("")
    public JsonResult<List<RoomCheckInListItemVO>> list(){
        log.debug("开始处理【查询入住登记列表】请求,无参数");
        List<RoomCheckInListItemVO> list = roomCheckInService.list();
        return JsonResult.ok(list);
    }

    @ApiOperation("根据所选的页数来分页查询")
    @ApiOperationSupport(order = 411)
    @ApiImplicitParam(name="pageNum",value = "需要跳过的记录数",required = true,dataType = "long")
    @GetMapping("/listByPageNum")
    public JsonResult<List<RoomCheckInListItemVO>> listByPageNum(@Range(min = 1,message = "查询入住登记失败,请填写有效的大于0的页数")
                                                             Long pageNum) {
        log.debug("开始处理【根据所选的页数来分页查询】的请求,参数:{}", pageNum);
        List<RoomCheckInListItemVO> list = roomCheckInService.listByPageNum(pageNum);
        return JsonResult.ok(list);
    }

    @ApiOperation("查询列表所有的数据以统计其数量")
    @ApiOperationSupport(order = 450)
    @GetMapping("/count")
    public JsonResult<List<RoomCheckInListCountVO>> listCount(){
        log.debug("开始处理【查询列表所有的数据以统计其数量】请求,无参数");
        List<RoomCheckInListCountVO> list = roomCheckInService.listCount();
        return JsonResult.ok(list);
    }
}
